use crate::co;
use crate::decl::*;
use crate::kernel::privs::*;
use crate::msg::*;
use crate::prelude::*;
use crate::user::privs::*;
pub struct CanUndo {}
unsafe impl MsgSend for CanUndo {
type RetType = bool;
fn convert_ret(&self, v: isize) -> Self::RetType {
v != 0
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::CANUNDO.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct CharFromPos {
pub coords: POINT,
}
unsafe impl MsgSend for CharFromPos {
type RetType = (u16, u16);
fn convert_ret(&self, v: isize) -> Self::RetType {
(LOWORD(v as _), HIWORD(v as _))
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::CHARFROMPOS.into(),
wparam: 0,
lparam: u32::from(self.coords) as _,
}
}
}
pub_struct_msg_empty! { EmptyUndoBuffer: co::EM::EMPTYUNDOBUFFER.into();
}
pub struct FmtLines {
pub insert_soft_line_breaks: bool,
}
unsafe impl MsgSend for FmtLines {
type RetType = bool;
fn convert_ret(&self, v: isize) -> Self::RetType {
v != 0
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::FMTLINES.into(),
wparam: self.insert_soft_line_breaks as _,
lparam: 0,
}
}
}
pub struct GetFirstVisibleLine {}
unsafe impl MsgSend for GetFirstVisibleLine {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETFIRSTVISIBLELINE.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetHandle {}
unsafe impl MsgSend for GetHandle {
type RetType = SysResult<HLOCAL>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|v| unsafe { HLOCAL::from_ptr(v as _) })
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETHANDLE.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetImeStatus {}
unsafe impl MsgSend for GetImeStatus {
type RetType = co::EIMES;
fn convert_ret(&self, v: isize) -> Self::RetType {
unsafe { co::EIMES::from_raw(v as _) }
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETIMESTATUS.into(),
wparam: 0x0001, lparam: 0,
}
}
}
pub struct GetLimitText {}
unsafe impl MsgSend for GetLimitText {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETLIMITTEXT.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetLine<'a> {
pub index: u16,
pub buffer: &'a mut WString,
}
unsafe impl<'a> MsgSend for GetLine<'a> {
type RetType = Option<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_none(v).map(|count| count as _)
}
fn as_generic_wm(&mut self) -> WndMsg {
self.buffer.fill_with_zero();
let buf_len = self.buffer.buf_len() - 1; self.buffer.as_mut_slice()
.iter_mut()
.next()
.map(|wchar| *wchar = buf_len as _); WndMsg {
msg_id: co::EM::GETLINE.into(),
wparam: self.index as _,
lparam: unsafe { self.buffer.as_mut_ptr() } as _,
}
}
}
pub struct GetLineCount {}
unsafe impl MsgSend for GetLineCount {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETLINECOUNT.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetMargins {}
unsafe impl MsgSend for GetMargins {
type RetType = SIZE;
fn convert_ret(&self, v: isize) -> Self::RetType {
SIZE::from(v as u32)
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETMARGINS.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetModify {}
unsafe impl MsgSend for GetModify {
type RetType = bool;
fn convert_ret(&self, v: isize) -> Self::RetType {
v != 0
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETMODIFY.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetPasswordChar {}
unsafe impl MsgSend for GetPasswordChar {
type RetType = Option<char>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_none(v).map(|c| unsafe { std::char::from_u32_unchecked(c as _) })
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETPASSWORDCHAR.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetRect<'a> {
pub rect: &'a mut RECT,
}
unsafe impl<'a> MsgSend for GetRect<'a> {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|_| ())
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETRECT.into(),
wparam: 0,
lparam: self.rect as *mut _ as _,
}
}
}
pub struct GetSel<'a, 'b> {
pub first_index: Option<&'a mut u32>,
pub past_last_index: Option<&'b mut u32>,
}
unsafe impl<'a, 'b> MsgSend for GetSel<'a, 'b> {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETSEL.into(),
wparam: self.first_index.as_mut().map_or(0, |r| r as *mut _ as _),
lparam: self.past_last_index.as_mut().map_or(0, |r| r as *mut _ as _),
}
}
}
pub struct GetThumb {}
unsafe impl MsgSend for GetThumb {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETTHUMB.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct GetWordBreakProc {}
unsafe impl MsgSend for GetWordBreakProc {
type RetType = Option<EDITWORDBREAKPROC>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_none(v).map(|p| unsafe { std::mem::transmute(p) })
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::GETTHUMB.into(),
wparam: 0,
lparam: 0,
}
}
}
pub struct LimitText {
pub max: Option<u32>,
}
unsafe impl MsgSend for LimitText {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::LIMITTEXT.into(),
wparam: self.max.unwrap_or(0) as _,
lparam: 0,
}
}
}
pub struct LineFromChar {
pub char_index: Option<u32>,
}
unsafe impl MsgSend for LineFromChar {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::LINEFROMCHAR.into(),
wparam: self.char_index.unwrap_or(-1i32 as _) as _,
lparam: 0,
}
}
}
pub struct LineIndex {
pub line_index: Option<u32>,
}
unsafe impl MsgSend for LineIndex {
type RetType = Option<u32>;
fn convert_ret(&self, v: isize) -> Self::RetType {
minus1_as_none(v).map(|v| v as _)
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::LINEINDEX.into(),
wparam: self.line_index.unwrap_or(-1i32 as _) as _,
lparam: 0,
}
}
}
pub struct LineLength {
pub char_index: Option<u32>,
}
unsafe impl MsgSend for LineLength {
type RetType = u32;
fn convert_ret(&self, v: isize) -> Self::RetType {
v as _
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::LINELENGTH.into(),
wparam: self.char_index.unwrap_or(-1i32 as _) as _,
lparam: 0,
}
}
}
pub struct LineScroll {
pub num_chars: u32,
pub num_lines: u32,
}
unsafe impl MsgSend for LineScroll {
type RetType = bool;
fn convert_ret(&self, v: isize) -> Self::RetType {
v != 0
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::LINESCROLL.into(),
wparam: self.num_chars as _,
lparam: self.num_lines as _,
}
}
}
pub struct PosFromChar {
pub char_index: u32,
}
unsafe impl MsgSend for PosFromChar {
type RetType = POINT;
fn convert_ret(&self, v: isize) -> Self::RetType {
POINT::from(v as u32)
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::POSFROMCHAR.into(),
wparam: self.char_index as _,
lparam: 0,
}
}
}
pub struct ReplaceSel {
pub can_be_undone: bool,
pub replacement_text: WString,
}
unsafe impl MsgSend for ReplaceSel {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::REPLACESEL.into(),
wparam: self.can_be_undone as _,
lparam: self.replacement_text.as_ptr() as _,
}
}
}
pub struct Scroll {
pub action: co::SB_EM,
}
unsafe impl MsgSend for Scroll {
type RetType = SysResult<u16>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|num_lines| num_lines as _)
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SCROLL.into(),
wparam: self.action.raw() as _,
lparam: 0,
}
}
}
pub_struct_msg_empty! { ScrollCaret: co::EM::SCROLLCARET.into();
}
pub struct SetHandle<'a> {
pub handle: &'a HLOCAL,
}
unsafe impl<'a> MsgSend for SetHandle<'a> {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETHANDLE.into(),
wparam: self.handle.ptr() as _,
lparam: 0,
}
}
}
pub struct SetImeStatus {
pub status: co::EIMES,
}
unsafe impl MsgSend for SetImeStatus {
type RetType = co::EIMES;
fn convert_ret(&self, v: isize) -> Self::RetType {
unsafe { co::EIMES::from_raw(v as _) }
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETIMESTATUS.into(),
wparam: 0x0001, lparam: self.status.raw() as _,
}
}
}
pub struct SetLimitText {
pub max_chars: Option<u32>,
}
unsafe impl MsgSend for SetLimitText {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETLIMITTEXT.into(),
wparam: self.max_chars.unwrap_or(0) as _,
lparam: 0,
}
}
}
pub struct SetMargins {
pub margins: co::EC,
pub size: SIZE,
}
unsafe impl MsgSend for SetMargins {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETMARGINS.into(),
wparam: self.margins.raw() as _,
lparam: u32::from(self.size) as _,
}
}
}
pub struct SetModify {
pub flag: bool,
}
unsafe impl MsgSend for SetModify {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETMODIFY.into(),
wparam: self.flag as _,
lparam: 0,
}
}
}
pub struct SetPasswordChar {
pub character: Option<char>,
}
unsafe impl MsgSend for SetPasswordChar {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETPASSWORDCHAR.into(),
wparam: self.character.map(|ch| ch as u32).unwrap_or(0) as _,
lparam: 0,
}
}
}
pub struct SetReadOnly {
pub read_only: bool,
}
unsafe impl MsgSend for SetReadOnly {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|_| ())
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETREADONLY.into(),
wparam: self.read_only as _,
lparam: 0,
}
}
}
pub struct SetRect<'a> {
pub is_absolute_coords: bool,
pub rect: Option<&'a RECT>,
}
unsafe impl<'a> MsgSend for SetRect<'a> {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETRECT.into(),
wparam: self.is_absolute_coords as _,
lparam: self.rect.map_or(0, |rect| rect as *const _ as _),
}
}
}
pub struct SetRectNp<'a> {
pub is_absolute_coords: bool,
pub rect: Option<&'a RECT>,
}
unsafe impl<'a> MsgSend for SetRectNp<'a> {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETRECTNP.into(),
wparam: self.is_absolute_coords as _,
lparam: self.rect.map_or(0, |rect| rect as *const _ as _),
}
}
}
pub struct SetSel {
pub start: i32,
pub end: i32,
}
unsafe impl MsgSend for SetSel {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETSEL.into(),
wparam: self.start as _,
lparam: self.end as _,
}
}
}
pub struct SetTabStops<'a> {
pub tab_stops: Option<&'a [i32]>,
}
unsafe impl<'a> MsgSend for SetTabStops<'a> {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|_| ())
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETTABSTOPS.into(),
wparam: self.tab_stops.map_or(0, |ts| ts.len() as _),
lparam: self.tab_stops.map_or(0, |ts| vec_ptr(ts) as _),
}
}
}
pub struct SetWordBreakProc {
pub proc: Option<EDITWORDBREAKPROC>,
}
unsafe impl MsgSend for SetWordBreakProc {
type RetType = ();
fn convert_ret(&self, _: isize) -> Self::RetType {
()
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::SETWORDBREAKPROC.into(),
wparam: 0,
lparam: self.proc.map_or(0, |proc| proc as _),
}
}
}
pub struct Undo {}
unsafe impl MsgSend for Undo {
type RetType = SysResult<()>;
fn convert_ret(&self, v: isize) -> Self::RetType {
zero_as_badargs(v).map(|_| ())
}
fn as_generic_wm(&mut self) -> WndMsg {
WndMsg {
msg_id: co::EM::UNDO.into(),
wparam: 0,
lparam: 0,
}
}
}